# -*- coding:UTF-8 -*-

# author:user
# contact: test@test.com
# datetime:2021/10/9 15:58
# software: PyCharm

"""
文件说明：
{
  "rasa_nlu_data": {
    "common_examples": [
        {"text": "i'm looking for a place in the north of town",
        "intent": "restaurant_search",
        "entities": [{
            "start": 31,
            "end": 36,
            "value": "north",
            "entity": "location"
          }]
        }
      ]
  }
}
"""
import json
from random import choice
import re
import ruamel.yaml

yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True

relations = {"有什么...功效", "产自...地", "有... 性味", "归...经", "组成", "治疗"}

with open(r"../data/original/medical.json", "r", encoding='utf-8') as fr:
    data = json.load(fr)

all_drug = set()

generation_question = [
    "请问[@](medicine)有什么功效",
    "[@](medicine)是用来干什么的",
    "[@](medicine)可以治疗什么",
    "请问[@](medicine)有什么疗效",
    "[@](medicine)是什么药",
    "[@](medicine)的功效和作用有哪些",
    "请问[@](medicine)的效果怎么样",
    "[@](medicine)治什么",
]

for drug in data:
    all_drug.add(drug["values"][0]["resourceName"])

question = []

for drug in all_drug:
    template = choice(generation_question)
    question.append(template.replace("@", drug))

yaml_path = "medical_ner.yaml"

data = {"nlu":{"intent":"medicals" ,"examples":["[dad]胜多负少","sadas","[撒旦大神]大大飒飒"]}}

with open(yaml_path, "w", encoding="utf-8") as fw:
    yaml.dump(data, fw)

fw = open("medical_ner1.yaml", 'w', encoding="utf-8")
with open(yaml_path, "r", encoding="utf-8") as fr:
    lines = fr.readlines()
    for line in lines:
        if "examples:" == line.strip():
            fw.write(line.rstrip()+" |\n")
        else:
            line = line.replace("'", "")
            fw.write(line)

fw.close()